﻿using AutoMapper;
using Hx.ADSyncPlatform.Infrastructure.Page;
using System.Collections.Generic;
using System.Linq;

namespace Hx.ADSyncPlatform.WebApi.AutoMapper
{
    public static class AutoMapperExtension
    {

        public static List<Target> MapToList<Source, Target>(this IMapper mapper, IEnumerable<Source> source)
        {
            return source.Select(n => mapper.Map<Source, Target>(n)).ToList();
        }
        public static PageResult<Target> MapToPage<Source, Target>(this IMapper mapper, PageResult<Source> source)
        {
            PageResult<Target> pageResult = new PageResult<Target>();
            IEnumerable<Source> tempSourceData = source.data.Select(n => n);
            pageResult.data = tempSourceData.Select(n => mapper.Map<Source, Target>(n)).ToList();
            pageResult.pagination = (Pagination)source.pagination.Clone();
            return pageResult;
        }
    }
}
